package com.chinairi.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinairi.common.annotation.DoPage;
import com.chinairi.common.controller.BaseController;
import com.chinairi.mall.model.ReqModel;
import com.chinairi.mall.service.IReqModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 消耗模型前端控制器，完成需求模型的增，删，改，查等功能
 * </p>
 * @author yyp
 * @since 2020-08-19
 */
@Api("需求模型")
@RestController
@RequestMapping("req-model")
public class ReqModelController extends BaseController {

    private static final long serialVersionUID = -3719073131663992225L;

   @Autowired
    private IReqModelService reqModelService;

    @ApiOperation("需求模型分页查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "modelName", value = "模型名称", required = false, paramType = "query", dataType = "string"),
                        @ApiImplicitParam(name = "modelDescription", value = "模型描述", required = false, paramType = "query", dataType = "string")})
    @DoPage
    @GetMapping("/pageReqModel")
    public List<Map<String, Object>> pageReqModel(ReqModel reqModel) {
        return reqModelService.pageReqModel(reqModel);
    }

    @ApiOperation("新增保存需求模型")
    @ApiImplicitParam(name="reqModel",value="需求模型",required = true,paramType = "form",dataType = "ReqModel")
    @PostMapping("/saveReqModel")
    public Map<String, Object> saveReqModel(ReqModel reqModel) {
     return reqModelService.saveReqModel(reqModel);
    }

    @ApiOperation("平均数量默认值")
    @ApiImplicitParam(name="modelId",value="模型id",required = true,paramType = "form",dataType = "String")
    @GetMapping("modelAverageValue/{modelId}")
    public Float modelAverageValue(@PathVariable String modelId) {
        return reqModelService.modelAverageValue(modelId);
    }

    @ApiOperation("修改需求模型")
    @ApiImplicitParam(name="reqModel",value="需求模型",required = true,paramType = "form",dataType = "ReqModel")
    @PutMapping("/updateReqModel")
    public Map<String, Object> updateReqModel(ReqModel reqModel) {
        return reqModelService.updateReqModel(reqModel);
    }

    @ApiOperation("删除需求模型")
    @ApiImplicitParam(name="modelId",value="模型id",required = true,paramType = "form",dataType = "String")
    @DeleteMapping("/deleteReqModel/{modelId}")
    public Map<String,Object> deleteReqModel(@PathVariable String modelId){
      return reqModelService.deleteReqModel(modelId);
    }
    @ApiOperation("根据id查询模型信息")
    @ApiImplicitParam(name="modelId",value="模型id",required = true,paramType = "form",dataType = "String")
    @GetMapping("reqModel")
    public Map<String, Object> getReqModel(String modelId) {
        return reqModelService.getReqModel(modelId);
    }

    @ApiOperation("重置模型状态")
    @ApiImplicitParam(name="modelId",value="模型id",required = true,paramType = "form",dataType = "String")
    @PutMapping("status/{modelId}")
    public Map<String, Object> removeReqModel(@PathVariable String modelId) {
        return reqModelService.removeReqModel(modelId);
    }

    @ApiOperation("导入模型明细")
    @ApiImplicitParams({@ApiImplicitParam(name = "reqModelDetailList", value = "模型明细集合", required = true, paramType = "form", dataType = "list"),
            @ApiImplicitParam(name = "modelId", value = "模型id", required = true, paramType = "path", dataType = "string")})
    @PostMapping("reqModelDetailList/{modelId}")
    public Map<String,Object> importReqModelDetail(ReqModel reqModel, @PathVariable String modelId) {
         return  reqModelService.importReqModelDetail(reqModel,modelId);
    }

    @ApiOperation("是否有效下拉")
    @GetMapping("listYesOrNo")
    public List<Map<String, Object>> listYesOrNo() {
        return reqModelService.listYesOrNo();
    }

    @ApiOperation("校验模型名称")
    @GetMapping("checkModelName")
    public Map<String,Object> checkModelName(String modelName) {
        return reqModelService.checkModelName(modelName);
    }
    }
